package com.sy.server.mapper;

import com.sy.server.dto.CostDTO;
import com.sy.server.model.Cost;
import com.sy.server.model.CostExample;
import com.sy.server.model.CostKey;
import java.util.List;
import java.util.Map;

import com.sy.server.vo.Day;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface CostMapper {
    @SelectProvider(type=CostSqlProvider.class, method="countByExample")
    int countByExample(CostExample example);

    @DeleteProvider(type=CostSqlProvider.class, method="deleteByExample")
    int deleteByExample(CostExample example);

    @Delete({
        "delete from cost",
        "where user_id = #{userId,jdbcType=INTEGER}",
          "and day = #{day,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(CostKey key);

    @Insert({
        "insert into cost (user_id, day, ",
        "eat, eat_detail, house, ",
        "house_detail, communication, ",
        "communication_detail, traffic, ",
        "traffic_detail, daily, ",
        "daily_detail, education, ",
        "education_detail, clothes, ",
        "clothes_detail, snacks, ",
        "snacks_detail, fruits, ",
        "fruits_detail, medical, ",
        "medical_detail, others, ",
        "others_detail, sum, ",
        "today_event)",
        "values (#{userId,jdbcType=INTEGER}, #{day,jdbcType=VARCHAR}, ",
        "#{eat,jdbcType=DOUBLE}, #{eatDetail,jdbcType=VARCHAR}, #{house,jdbcType=DOUBLE}, ",
        "#{houseDetail,jdbcType=VARCHAR}, #{communication,jdbcType=DOUBLE}, ",
        "#{communicationDetail,jdbcType=VARCHAR}, #{traffic,jdbcType=DOUBLE}, ",
        "#{trafficDetail,jdbcType=VARCHAR}, #{daily,jdbcType=DOUBLE}, ",
        "#{dailyDetail,jdbcType=VARCHAR}, #{education,jdbcType=DOUBLE}, ",
        "#{educationDetail,jdbcType=VARCHAR}, #{clothes,jdbcType=DOUBLE}, ",
        "#{clothesDetail,jdbcType=VARCHAR}, #{snacks,jdbcType=DOUBLE}, ",
        "#{snacksDetail,jdbcType=VARCHAR}, #{fruits,jdbcType=DOUBLE}, ",
        "#{fruitsDetail,jdbcType=VARCHAR}, #{medical,jdbcType=DOUBLE}, ",
        "#{medicalDetail,jdbcType=VARCHAR}, #{others,jdbcType=DOUBLE}, ",
        "#{othersDetail,jdbcType=VARCHAR}, #{sum,jdbcType=DOUBLE}, ",
        "#{todayEvent,jdbcType=VARCHAR})"
    })
    int insert(Cost record);

    @InsertProvider(type=CostSqlProvider.class, method="insertSelective")
    int insertSelective(Cost record);

    @SelectProvider(type=CostSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="day", property="day", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="eat", property="eat", jdbcType=JdbcType.DOUBLE),
        @Result(column="eat_detail", property="eatDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="house", property="house", jdbcType=JdbcType.DOUBLE),
        @Result(column="house_detail", property="houseDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="communication", property="communication", jdbcType=JdbcType.DOUBLE),
        @Result(column="communication_detail", property="communicationDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="traffic", property="traffic", jdbcType=JdbcType.DOUBLE),
        @Result(column="traffic_detail", property="trafficDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="daily", property="daily", jdbcType=JdbcType.DOUBLE),
        @Result(column="daily_detail", property="dailyDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="education", property="education", jdbcType=JdbcType.DOUBLE),
        @Result(column="education_detail", property="educationDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="clothes", property="clothes", jdbcType=JdbcType.DOUBLE),
        @Result(column="clothes_detail", property="clothesDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="snacks", property="snacks", jdbcType=JdbcType.DOUBLE),
        @Result(column="snacks_detail", property="snacksDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="fruits", property="fruits", jdbcType=JdbcType.DOUBLE),
        @Result(column="fruits_detail", property="fruitsDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="medical", property="medical", jdbcType=JdbcType.DOUBLE),
        @Result(column="medical_detail", property="medicalDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="others", property="others", jdbcType=JdbcType.DOUBLE),
        @Result(column="others_detail", property="othersDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="sum", property="sum", jdbcType=JdbcType.DOUBLE),
        @Result(column="today_event", property="todayEvent", jdbcType=JdbcType.VARCHAR)
    })
    List<Cost> selectByExample(CostExample example);

    @Select({
            "select sum",
            "from cost",
            "where user_id=#{userId,jdbcType=INTEGER}",
            "and day between #{beginDate,jdbcType=VARCHAR} and #{endDate,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column = "sum",jdbcType = JdbcType.DOUBLE)
    })
    List<Double> selectTotal(Integer userId,String beginDate,String endDate);

    @Select({
            "select sum,day",
            "from cost",
            "where user_id=#{userId,jdbcType=INTEGER}",
            "and day between #{beginDate,jdbcType=VARCHAR} and #{endDate,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column = "sum",property = "sum",jdbcType = JdbcType.DOUBLE),
            @Result(column = "day",property = "day",jdbcType = JdbcType.VARCHAR)
    })
    List<CostDTO> selectTotalWithDay(Integer userId,String beginDate,String endDate);

    @Select({
        "select",
        "user_id, day, eat, eat_detail, house, house_detail, communication, communication_detail, ",
        "traffic, traffic_detail, daily, daily_detail, education, education_detail, clothes, ",
        "clothes_detail, snacks, snacks_detail, fruits, fruits_detail, medical, medical_detail, ",
        "others, others_detail, sum, today_event",
        "from cost",
        "where user_id = #{userId,jdbcType=INTEGER}",
          "and day = #{day,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="day", property="day", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="eat", property="eat", jdbcType=JdbcType.DOUBLE),
        @Result(column="eat_detail", property="eatDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="house", property="house", jdbcType=JdbcType.DOUBLE),
        @Result(column="house_detail", property="houseDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="communication", property="communication", jdbcType=JdbcType.DOUBLE),
        @Result(column="communication_detail", property="communicationDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="traffic", property="traffic", jdbcType=JdbcType.DOUBLE),
        @Result(column="traffic_detail", property="trafficDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="daily", property="daily", jdbcType=JdbcType.DOUBLE),
        @Result(column="daily_detail", property="dailyDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="education", property="education", jdbcType=JdbcType.DOUBLE),
        @Result(column="education_detail", property="educationDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="clothes", property="clothes", jdbcType=JdbcType.DOUBLE),
        @Result(column="clothes_detail", property="clothesDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="snacks", property="snacks", jdbcType=JdbcType.DOUBLE),
        @Result(column="snacks_detail", property="snacksDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="fruits", property="fruits", jdbcType=JdbcType.DOUBLE),
        @Result(column="fruits_detail", property="fruitsDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="medical", property="medical", jdbcType=JdbcType.DOUBLE),
        @Result(column="medical_detail", property="medicalDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="others", property="others", jdbcType=JdbcType.DOUBLE),
        @Result(column="others_detail", property="othersDetail", jdbcType=JdbcType.VARCHAR),
        @Result(column="sum", property="sum", jdbcType=JdbcType.DOUBLE),
        @Result(column="today_event", property="todayEvent", jdbcType=JdbcType.VARCHAR)
    })
    Cost selectByPrimaryKey(CostKey key);

    @Select({
            "select avg(sum) as a",
            "from cost",
            "where user_id = #{userId,jdbcType=INTEGER}",
            "and day between #{beginDate,jdbcType=VARCHAR} and #{endDate,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column = "a",jdbcType = JdbcType.DOUBLE)
    })
    double selectXDaysAvg(Integer userId,String beginDate,String endDate);

    @UpdateProvider(type=CostSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Cost record, @Param("example") CostExample example);

    @UpdateProvider(type=CostSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Cost record, @Param("example") CostExample example);

    @UpdateProvider(type=CostSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Cost record);

    @Update({
        "update cost",
        "set eat = #{eat,jdbcType=DOUBLE},",
          "eat_detail = #{eatDetail,jdbcType=VARCHAR},",
          "house = #{house,jdbcType=DOUBLE},",
          "house_detail = #{houseDetail,jdbcType=VARCHAR},",
          "communication = #{communication,jdbcType=DOUBLE},",
          "communication_detail = #{communicationDetail,jdbcType=VARCHAR},",
          "traffic = #{traffic,jdbcType=DOUBLE},",
          "traffic_detail = #{trafficDetail,jdbcType=VARCHAR},",
          "daily = #{daily,jdbcType=DOUBLE},",
          "daily_detail = #{dailyDetail,jdbcType=VARCHAR},",
          "education = #{education,jdbcType=DOUBLE},",
          "education_detail = #{educationDetail,jdbcType=VARCHAR},",
          "clothes = #{clothes,jdbcType=DOUBLE},",
          "clothes_detail = #{clothesDetail,jdbcType=VARCHAR},",
          "snacks = #{snacks,jdbcType=DOUBLE},",
          "snacks_detail = #{snacksDetail,jdbcType=VARCHAR},",
          "fruits = #{fruits,jdbcType=DOUBLE},",
          "fruits_detail = #{fruitsDetail,jdbcType=VARCHAR},",
          "medical = #{medical,jdbcType=DOUBLE},",
          "medical_detail = #{medicalDetail,jdbcType=VARCHAR},",
          "others = #{others,jdbcType=DOUBLE},",
          "others_detail = #{othersDetail,jdbcType=VARCHAR},",
          "sum = #{sum,jdbcType=DOUBLE},",
          "today_event = #{todayEvent,jdbcType=VARCHAR}",
        "where user_id = #{userId,jdbcType=INTEGER}",
          "and day = #{day,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(Cost record);

}